﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using OMS.OMSService;
using OMS.Models;

namespace OMS.Filters
{
    public class RoleAttribute : AuthorizeAttribute
    {
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            if (!httpContext.Request.IsAuthenticated)
                return false;

            Service1 service = new Service1();
            int userId = 1; //TODO: GetFrom httpContext.User.Id
            UserModel userModel = service.GetUserById(userId, true);

            if (userModel.Role == this.Roles.Split()[0])
                return true;
            else
                return false;
            //return base.AuthorizeCore(httpContext);
        }
    }
}